#!/usr/bin/env python
import commands, subprocess, re, time, sys, csv
from datetime import datetime
from os.path import exists

number_re = "+([0-9]+\.[01-9]+|[0-9]+)"

def get_result_elasped_time(log):
    try:
        #return re.findall('Elasped time : '+number_re, log)[0]
        val = re.findall('thread0 latency: '+number_re, log)[0]
        return val
    except:
        return '-'

log = open('./log2.csv', 'w+')


for intervals in ['0']:
    #for operations in ['1000','10000','100000','1000000']:
    for operations in ['1000000']:
        log.write('operation '+operations+',8,16,24,32,\n')
        for pushRatio in ['0.5','1']:
            #for version in ['CCoarseGrainedLockStack','CLockFreeStack','CEliminationBackoffStack','CCombTreeStack']:  #'naive','TAS','TTAS','Exponential backoff','Anderson Queue lock'
            for version in ['CCoarseGrainedLockStack','CLockFreeStack','CEliminationBackoffStack','CCombTreeStack']:  #'naive','TAS','TTAS','Exponential backoff','Anderson Queue lock'
                log.write(version+'-'+pushRatio+',');
                for participants in ['8','16','24','32']:
                    f = open('./log/'+version+'.'+participants+'-'+pushRatio+'-'+operations+'-'+intervals+'.log', 'r')
                    log_data = f.read()
                    ElapsedTime = get_result_elasped_time(log_data)
                    log.write(ElapsedTime+',')
                log.write('\n')
log.close()

